﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1.Mymyti;
using WindowsFormsApplication1.Mypay;

using System.Globalization;
using System.Security.Cryptography;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MymytiServiceClient m = new MymytiServiceClient();
            Mymyti.userInfo user = new Mymyti.userInfo();
            //config.RecordLog(Phone, Name, Code, "6. 实例化userInfo成功");
            user.name = "黄德志";  
            user.mobile = "15106020935";//
            //user.reg_type = "1";//注册类别
            //user.event_type = "9";//注册活动类型 Event_type
            //user.event_code = "1";//活动码 Event_code
            //user.mg_no = "100000052174562";//推荐人账户号 Mg_no
            //user.mg_level = "3"; //推荐人级别 MG_level
            //user.taboo = "1";//服务禁忌 taboo
            //user.habit = "1";//客户特殊嗜好 habit


            Mymyti.userRegReq userReq = new Mymyti.userRegReq();
            //config.RecordLog(Phone, Name, Code, "7. 实例化userRegReq成功");
            userReq.term_no = "160315JK";    //160315YK银 渠道码（如果渠道是门店，传门店号，如果渠道是名片：传“MP2WM001”）
                                  //config.RecordLog(Phone, Name, Code, "8. 渠道码赋值" + postParams.ClientCd);
            userReq.resv1 = "";
            userReq.resv2 = "";
            userReq.resv3 = "";
            userReq.resv4 = "";
            userReq.term_seq = DateTime.Now.ToString("yyyyMMddHHmmss");
            userReq.userInfo = user;
            userReq.opr_no = "CRM";
            //192.168.210.214


            Mymyti.MymytiServiceClient client = new Mymyti.MymytiServiceClient();
            //config.RecordLog(Phone, Name, Code, "9. 实例化MymytiServiceImplService成功");
            Mymyti.userRegResp userResp = client.userRegShortcut(userReq);
            //config.RecordLog(Phone, Name, Code, "10. 调用注册接口成功！！！！");
            if (userResp.resCode == 0)  //注册成功
            {
                // 2.查询会员和卡信息 QueryUserList
                queryUserReq q = new queryUserReq();
                q.mobile = user.mobile;
               // q.card_no = "1945295122";
                q.term_no = "160315JK";
                q.opr_no = "CRM";
                q.term_seq = System.DateTime.Now.ToString();
                // QueryUserListResp 
                queryUserListResp result = client.queryUserList(q);
                // //config.RecordLog(Phone, Name, Code, "11. 注册接口返回0，注册成功");
                // string UserId = userResp.user_id;
                // //config.RecordLog(Phone, Name, Code, "12. 获取user_id");
                //// string x = config.SetRegInfo(postParams.QrCodeID, Phone, Name, "Register", userResp.resCode.ToString(), UserId);
                // //config.RecordLog(Phone, Name, Code, "13. 记录注册信息！");
                // if (x == "Success")
                // {
                //     //config.RecordLog(Phone, Name, Code, "14. 记录注册信息返回Success");
                //     //SendPayment(Phone, UserId);
                //     ////config.RecordLog(Phone, Name, Code, "15. 调用赠送优惠券成功");
                //    // SendKuaiDi(Phone, UserId);
                //     //config.RecordLog(Phone, Name, Code, "16. 调用赠送快滴券成功");
                //    // SendDanChe(Phone, UserId);
                //     //config.RecordLog(Phone, Name, Code, "17. 调用赠送单车券成功，全部成功，返回用户密码！");
                //    // return "{\"success\":true,\"message\":\"" + userResp.password + "\"}";
                // }
                // else if (x == "Existed")
                // {
                //     //config.RecordLog(Phone, Name, Code, "18. 用户注册信息存在，返回注册失败");
                //    // return "{\"success\":false,\"message\":\"会员日志已存在，注册失败！\"}";
                // }
                // else
                // {
                //     //config.RecordLog(Phone, Name, Code, "19. 未知原因错误");
                //     //return "{\"success\":false,\"message\":\"未知错误！\"}";
                // }

                //100000046837583 User_level_code 
                //4.	修改会员信息 ModifyUser ModifyUserReq
                //modifyUserReq mu = new modifyUserReq();
                //userInfo i = new userInfo();

                //i.user_id = "100000046837583";
                //i.name = "陈乐";
                //i.user_level_code = "3";
                //i.sex = "1";
                //i.mobile = "13585952046";
                //mu.userInfo = i;
                //mu.term_seq = System.DateTime.Now.ToString();
                //mu.term_no = "21129999";
                //mu.opr_no = "CRM";
                //m.modifyUser(mu);


            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //2016091801
            MymytiServiceClient m = new MymytiServiceClient();
            modifyUserReq mu = new modifyUserReq();
            userInfo i = new userInfo();

            i.user_id = "100000055504909";
            i.name = "陈乐";
            i.user_level_code = "4";
            i.sex = "1";
            i.mobile = "13371939539";
            i.email = "lechen@homeinns.com";
            mu.userInfo = i;
            mu.term_seq = System.DateTime.Now.ToString();
            mu.term_no = "21129999";
            mu.opr_no = "CRM";
            modifyUserResp result = m.modifyUser(mu);
            //2013122602


 

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //            朱敏 13640691001   铂金    100000009628975
            //陈乐 13771939539   金      100000009628974
            //吴翔 13918613472   银     100000000965786
            //172.23.100.225
            Mymyti.MymytiServiceClient client = new Mymyti.MymytiServiceClient();
            queryUserReq q = new queryUserReq();
            // q.mobile = "13564185841";
            // q.card_no = "1945295122";
            q.id_no = "08250692";
            q.term_no = "160315JK";
            q.opr_no = "CRM";
            q.term_seq = System.DateTime.Now.ToString();
            queryUserListResp result = client.queryUserList(q);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            disTicketReq r = new disTicketReq();
            r.term_seq = System.DateTime.Now.ToString();
            r.term_no = "21129999";
            r.opr_no = "CRM";
            r.user_id = "100000055504909"; //100000055504909
            r.type_number = "2016122902";// "2016110402";
            r.num = "1";
            PaymentServiceClient p = new PaymentServiceClient();
            disTicketResp dip = p.disTicketByTypeNumber(r);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //加密
            string test = "123";
            DES d = new DES();
            //MD5Encrypt(string pToEncrypt, string sKey)
            string result = d.MD5Encrypt(test,"12345678");
        }

        private void button6_Click(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
//            1.加积分 RecordScore
//请求参数：RecordScoreReq

            Mymyti.MymytiServiceClient client = new Mymyti.MymytiServiceClient();
            recordScoreReq q = new recordScoreReq();
            q.id_no = "310107198508260911";//证件号
            q.id_type = "0";
            q.acc_no = "100000055504909";
            q.score = "1";
            q.term_no = "21129999";
            q.opr_no = "CRM";
            q.memo = "测试";
            q.term_seq = System.DateTime.Now.ToString();
            recordScoreResp result = client.recordScore(q);
        }
    }

    public class DES
    {
        // 创建Key
        public string GenerateKey()
        {
            DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();
            return ASCIIEncoding.ASCII.GetString(desCrypto.Key);
        }
        ///MD5加密
        public string MD5Encrypt(string pToEncrypt, string sKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            StringBuilder ret = new StringBuilder();
            foreach (byte b in ms.ToArray())
            {
                ret.AppendFormat("{0:X2}", b);
            }
            ret.ToString();
            return ret.ToString();


        }

        ///MD5解密
        public string MD5Decrypt(string pToDecrypt, string sKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();

            byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
            for (int x = 0; x < pToDecrypt.Length / 2; x++)
            {
                int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                inputByteArray[x] = (byte)i;
            }

            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            StringBuilder ret = new StringBuilder();

            return System.Text.Encoding.Default.GetString(ms.ToArray());
        }



    }
}
